package configcenter.zookeeper.curator.api.retry;


import common.model.MagicUrl;
import configcenter.zookeeper.curator.NotifyListener;
import configcenter.zookeeper.curator.api.FailbackRegistry;
import remoting.timer.Timeout;

/**
 * FailedSubscribedTask
 */
public final class FailedSubscribedTask extends AbstractRetryTask {

    private static final String NAME = "retry subscribe";

    private final NotifyListener listener;

    public FailedSubscribedTask(MagicUrl url, FailbackRegistry registry, NotifyListener listener) {
        super(url, registry, NAME);
        if (listener == null) {
            throw new IllegalArgumentException();
        }
        this.listener = listener;
    }

    @Override
    protected void doRetry(MagicUrl url, FailbackRegistry registry, Timeout timeout) {
        registry.doSubscribe(url, listener);
        registry.removeFailedSubscribedTask(url, listener);
    }
}
